package cn.humaohua.study.yanmo_design_pattern.ch20;

import org.apache.commons.lang3.StringUtils;

/**
 * 封装授权数据中重复出现部分的享元对象
 */
public class AuthorizationFlyweight implements Flyweight {
    //内部状态：安全实体
    private String securityEntity;
    //内部状态：权限
    private String permit;

    public AuthorizationFlyweight(String state) {
        String[] arr = state.split(",");
        setSecurityEntity(arr[0]);
        setPermit(arr[1]);
    }

    @Override
    public boolean match(String securityEntity, String permit) {
        if (StringUtils.equals(this.permit, permit) && StringUtils.equals(this.securityEntity, securityEntity)) {
            return true;
        }
        return false;
    }

    public String getSecurityEntity() {
        return securityEntity;
    }

    public void setSecurityEntity(String securityEntity) {
        this.securityEntity = securityEntity;
    }

    public String getPermit() {
        return permit;
    }

    public void setPermit(String permit) {
        this.permit = permit;
    }
}
